Creation date: 2025/08/04 Modified Date & Time: 2025/08/27 @ 08:29

1 Load Libraries

library(shiny)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(DiagrammeR)

2 Data

  • Note Data is in TEST-GOE-Monitor.xlsx file, with one worksheet for Data, and one worksheet for Site info
  • Save each worksheet to 2 separate csv files Site-Data-TEST-GOE-Monitor.csv & SiteData-TEST-GOE-Monitor.csv

2.1 Load Data

  • Data Cleaning to ensure no space at beginning of any text values and column headings Note: SiteDetails-TEST-GOE-Monitor.csv has space in front of values NEED TO change TEST-GOE-Monitor.xlsx excel file first, then resave as csv
# Site Data
geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")
# Site Details
Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")

2.2 Data Discovery

2.3 Column Names Data

colnames(geo_eccc)
## [1] "Subregion"                    "Site"                        
## [3] "Proportion_of_native_species" "Cultural_species_richness"   
## [5] "Exotic_species"               "Trampling"                   
## [7] "Herbivory"                    "Composite_Index"             
## [9] "Year"

2.4 Column Names Sites

colnames(Sites_eccc)
## [1] "Subregion"             "Site"                  "Land.Manager"         
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"              
## [7] "Lat"                   "Lng"

3 Data Manipulation

3.1 proportion to Percentage_of_native_species

# using scales creates % character instead of number
# Percentage_of_native_species <- scales::percent(geo_eccc$Proportion_of_native_species)
# Percentage_of_native_species 

Percentage_ns <- geo_eccc$Proportion_of_native_species * 100
Percentage_ns
##  [1] 94 55 77 66 75 53 45 65 62 58 45 67 62 61 32 64 49 41 47 34 34 44 54 37

3.2 add Percentage_ns data to column

Click to see results of data

# https://sparkbyexamples.com/r-programming/add-column-to-dataframe-in-r/
# geo_eccc_1 <- cbind(geo_eccc, Percentage_of_native_species)
# geo_eccc_1

geo_eccc <- cbind(geo_eccc, Percentage_ns)
geo_eccc
##            Subregion               Site Proportion_of_native_species
## 1       Gulf Islands Anniversary Island                         0.94
## 2       Gulf Islands               AVNR                         0.55
## 3       Gulf Islands    Brackman Island                         0.77
## 4       Gulf Islands         Crows Nest                         0.66
## 5       Gulf Islands       Dock Islet N                         0.75
## 6       Gulf Islands        Eagle Islet                         0.53
## 7       Gulf Islands         Mt Maxwell                         0.45
## 8       Gulf Islands          Owl Islet                         0.65
## 9       Gulf Islands         Reay Islet                         0.62
## 10      Gulf Islands     Retreat Island                         0.58
## 11      Gulf Islands          Rum Islet                         0.45
## 12      Gulf Islands           SISCENEM                         0.67
## 13 Saanich Peninsula     Bear Hill Park                         0.62
## 14 Saanich Peninsula         Camas Hill                         0.61
## 15 Saanich Peninsula Gonzales Hill Park                         0.32
## 16 Saanich Peninsula          Gore Park                         0.64
## 17 Saanich Peninsula      Highrock Park                         0.49
## 18 Saanich Peninsula     Mill Hill Park                         0.41
## 19 Saanich Peninsula     Oak Haven Park                         0.47
## 20 Saanich Peninsula         Scafe Hill                         0.34
## 21 Saanich Peninsula       Seymour Hill                         0.34
## 22 Saanich Peninsula       Stewart Hill                         0.44
## 23 Saanich Peninsula       Trial Island                         0.54
## 24 Saanich Peninsula       Uplands Park                         0.37
##    Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1                       2.71           0.17      5.00      1.14             1.8
## 2                       1.30          57.19      4.70     36.50             0.6
## 3                       2.80          11.17      5.40      0.00             2.0
## 4                       1.07          31.51      1.64     26.71             1.0
## 5                       3.60           8.80     12.20      0.10             1.6
## 6                       0.80          28.25     16.60      0.00             0.8
## 7                       0.42          64.30     10.00      6.00             0.2
## 8                       2.00          27.72     10.67      0.67             1.4
## 9                       3.60          11.51     11.00      8.00             1.0
## 10                      2.33          33.00     32.33      0.00             1.0
## 11                      1.00          73.21     22.20     70.80             0.0
## 12                      3.40          16.12     12.80      0.50             1.6
## 13                      1.86          24.46      7.57      9.50             1.0
## 14                      2.43          27.19      7.71      4.71             1.4
## 15                      1.00          83.16     10.40      1.20             0.4
## 16                      4.40           7.35      6.20      1.60             1.6
## 17                      1.60          37.10      8.20      1.20             1.0
## 18                      1.56          46.33     14.33     25.67             0.4
## 19                      1.50          34.60      1.88     12.75             1.0
## 20                      1.40          55.35     10.20      1.40             0.4
## 21                      2.20          65.99      9.20      0.20             0.8
## 22                      1.00          79.56      4.80      0.80             0.6
## 23                      3.57          30.73      2.00      0.14             1.6
## 24                      1.45          49.38      2.36      5.82             1.0
##    Year Percentage_ns
## 1  2023            94
## 2  2023            55
## 3  2023            77
## 4  2023            66
## 5  2023            75
## 6  2023            53
## 7  2023            45
## 8  2023            65
## 9  2023            62
## 10 2023            58
## 11 2023            45
## 12 2023            67
## 13 2023            62
## 14 2023            61
## 15 2023            32
## 16 2023            64
## 17 2023            49
## 18 2023            41
## 19 2023            47
## 20 2023            34
## 21 2023            34
## 22 2023            44
## 23 2023            54
## 24 2023            37

3.3 Check data structure of new column

str(geo_eccc)
## 'data.frame':    24 obs. of  10 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 77 66 75 53 45 65 62 58 ...

3.4 Data Structure Data

  • make sure each column is same data type in both data files
str(geo_eccc)
## 'data.frame':    24 obs. of  10 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 77 66 75 53 45 65 62 58 ...

3.5 Data Structure Sites

  • make sure each column is same data type
str(Sites_eccc)
## 'data.frame':    24 obs. of  8 variables:
##  $ Subregion            : chr  "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" "Saanich Peninsula" ...
##  $ Site                 : chr  "Gore Park" "Highrock Park" "Mill Hill Park" "Oak Haven Park" ...
##  $ Land.Manager         : chr  "Central Saanich" "City of Esquimalt" "CRD" "CRD" ...
##  $ Main.Restoration.Type: chr  "invasive removal" "invasive removal" "invasive removal" "invasive removal" ...
##  $ Restoration.Intensity: chr  "moderate" "low" "high" "high" ...
##  $ Area.ha              : num  0.74 2.88 16.66 3.16 3.36 ...
##  $ Lat                  : num  48.5 48.4 48.5 48.6 48.5 ...
##  $ Lng                  : num  -123 -123 -123 -123 -123 ...

3.6 Combine Dataframes

  • first make sure they have the same number of rows
length(unique(geo_eccc$Site))
## [1] 24
length(unique(Sites_eccc$Site))
## [1] 24

3.6.1 Arrange Order

  • Site details Site names are in different order than Site Data, so put each site in alphabetical order first
# tidyverse
# https://stackoverflow.com/questions/68989228/sort-dataframe-by-column-value-r
Sites_eccc_1 <- Sites_eccc %>% arrange(Sites_eccc$Site)
geo_eccc_1 <- geo_eccc %>% arrange(geo_eccc$Site)

3.6.2 cbind arranged df works

  • (merge doesn’t work, leaves columns empty)
geo_eccc_sites <- cbind(Sites_eccc_1, geo_eccc_1)
names(geo_eccc_sites)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land.Manager"                 "Main.Restoration.Type"       
##  [5] "Restoration.Intensity"        "Area.ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Subregion"                    "Site"                        
## [11] "Proportion_of_native_species" "Cultural_species_richness"   
## [13] "Exotic_species"               "Trampling"                   
## [15] "Herbivory"                    "Composite_Index"             
## [17] "Year"                         "Percentage_ns"

3.6.3 remove duplicate columns

  • now there are 2 columns with same name for, Subregion, Site
# https://stackoverflow.com/questions/7072159/how-do-you-remove-columns-from-a-data-frame
geo_eccc_sites_1 <- geo_eccc_sites[c(-9,-10)]
names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land.Manager"                 "Main.Restoration.Type"       
##  [5] "Restoration.Intensity"        "Area.ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"

3.6.4 Rename columns with . using base R

names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Land.Manager"] <- "Land_Manager"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Main.Restoration.Type"] <- "Main_Restoration_Type"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Restoration.Intensity"] <- "Restoration_Intensity"
names(geo_eccc_sites_1)[names(geo_eccc_sites_1) == "Area.ha"] <- "Area_ha"

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"

3.6.5 Create and save new csv file with both datasets

write.csv(geo_eccc_sites_1, "geo_eccc_all_site_data.csv", row.names = FALSE)

4 Plots

4.1 Site by Percentage Native Species

site_natsp <- ggplot(geo_eccc, 
                    aes(x = Site, y = Percentage_ns)) +
                    geom_point(shape = 18, size = 2) +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Site by Percentage Native Species',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp

4.2 Site by Composite_Index

site_natsp <- ggplot(geo_eccc, 
                    aes(x = Site, y = Composite_Index)) +
                    geom_point(shape = 18, size = 2) +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Site by Composite Index',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
site_natsp

4.3 TEST DOESn’t Reorder Site by Restoration_Intensity

  • note Reay Islet was showing a separate High, so in original csv I copied High value from another site, aslo Scafe Hill had a different low value …
  • also all high values have a space in front … change all …
  • Having trouble ordering Restoration_Intensity values … see next example
Click to see results of TEST

# names(geo_eccc_sites_1)
# str(geo_eccc_sites_1)
# unique(geo_eccc_sites_1$Restoration_Intensity)
# 
# # change character to factor
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# 
# # WORKS !!!
# Restoration_Intensity_order <- c("high", "moderate", "low", "minimal")
# arranged_geo_eccc_sites_1 <- geo_eccc_sites_1 %>% 
#   arrange(factor(Restoration_Intensity, levels = Restoration_Intensity_order))
# arranged_geo_eccc_sites_1
# str(arranged_geo_eccc_sites_1)
# 
# # still not showing the order
# site_restInt <- ggplot(arranged_geo_eccc_sites_1,
#        aes(x = Site, y = Restoration_Intensity, color = Subregion)) +
#                     geom_point(shape = 18, size = 2) +
#   #geom_bar(stat="identity") +
#                     theme_minimal() + #get rid of grey background and tick marks 
#                     theme(legend.position="bottom") + #remove legend 
#                     theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
#                     labs(title='Plotting Site by Restoration_Intensity',
#                       subtitle='ECCC',
#                       caption = "Chart by Wendy Anthony \n 2025-08-20")
# site_restInt

# ggplotly(site_restInt)

4.4 ORDER NOT WORKING TEST Site by Restoration_Intensity and Exotic_species

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
str(geo_eccc_sites_1)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high"     "moderate" "low"      "minimal"
str(geo_eccc_sites_2)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]

site_restInt_exotic <- ggplot(geo_eccc_sites_2,
       aes(x = Exotic_species, y = Restoration_Intensity, color = Site)) +
                    geom_point(shape = 18, size = 2) +
  #geom_bar(stat="identity") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend legen won't stick to bottom with ggplotly
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Site by Restoration_Intensity & Exotic Species',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-20")
site_restInt_exotic

# ggplotly(site_restInt_exotic)
# change ggplotly legend to bottom
  # %>% 
 #      plotly::layout(legend=list(x=0, 
 #                                 xanchor='left',
 #                                 yanchor='bottom',
 #                                 orientation='h'))    

4.5 ORDER WORKs Point Plot Site by Restoration_Intensity

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
# Reorder following a precise order
# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)

# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high"     "moderate" "low"      "minimal"
str(geo_eccc_sites_2)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]

# values in order now -- ?? how to change to reverse order 
site_restInt <- ggplot(geo_eccc_sites_2,
       aes(x = Site, y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Subregion)) +
  # reorder y variable axis
  # https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
                    geom_point(shape = 18, size = 2) +
  #geom_bar(stat="identity") +
  # Replace default palette of pink & blue
  scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="bottom") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Sites by Restoration Intensity',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-22", x = "Site", y = "Restoration Intensity")

site_restInt

ggplotly(site_restInt)

4.6 Change x axis ORDER WORKs Point Plot Site by Restoration_Intensity

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
# Reorder following a precise order
# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)

# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# create new df to create desired levels
geo_eccc_sites_2 <- geo_eccc_sites_1
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high"     "moderate" "low"      "minimal"
str(geo_eccc_sites_2)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]

# values in order now -- ?? how to change to reverse order 
site_restInt_x <- ggplot(geo_eccc_sites_2,
       aes(x = reorder(Site, 
                       # -desc reverses descending
                       -desc(Restoration_Intensity)), 
           y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Subregion)) +
  # reorder y variable axis
  # https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
                    geom_point(shape = 18, size = 2) +
  #geom_bar(stat="identity") +
  # Replace default palette of pink & blue
  # makes ggploty legend show (Saanich Peninsula,1)
#  scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="bottom") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Site by Restoration_Intensity',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-26",
                      x = "Site", y = "Restoration_Intensity")
site_restInt_x

ggplotly(site_restInt_x)

4.7 BAR Plot WORKS Site by Restoration_Intensity

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
# Reorder following a precise order
# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
# https://stackoverflow.com/questions/18413756/re-ordering-factor-levels-in-data-frame
# mydf$task <- factor(mydf$task, levels = c("up", "down", "left", "right", "front", "back"))
#geo_eccc_sites_1$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = #c("high", "moderate", "low", "minimal"))
str(geo_eccc_sites_1)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
# change character to factor
# str(geo_eccc_sites_1)
# geo_eccc_sites_1$Restoration_Intensity <- as.factor(geo_eccc_sites_1$Restoration_Intensity)
# str(geo_eccc_sites_1)
# # change factor to character
# geo_eccc_sites_1 <- data.frame(lapply(geo_eccc_sites_1, as.character), stringsAsFactors=FALSE)
# str(geo_eccc_sites_1)

# Step 1
desired_levels <- c("high", "moderate", "low", "minimal")
# this changes data type from character to factor
geo_eccc_sites_2$Restoration_Intensity <- factor(geo_eccc_sites_1$Restoration_Intensity, levels = desired_levels)
print(levels(geo_eccc_sites_2$Restoration_Intensity)) # New order of levels
## [1] "high"     "moderate" "low"      "minimal"
str(geo_eccc_sites_2)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "Brackman Island" "Camas Hill" "Crows Nest" ...
##  $ Land_Manager                : chr  "GINPR" "GINPR" "HAT" "Trinity Western University" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "invasive removal" "invasive removal" "herbivore reduction" ...
##  $ Restoration_Intensity       : Factor w/ 4 levels "high","moderate",..: 1 4 3 1 1 1 1 1 3 2 ...
##  $ Area_ha                     : num  4.39 4.41 10.1 15.34 0.54 ...
##  $ Lat                         : num  48.8 48.7 48.4 48.8 48.7 ...
##  $ Lng                         : num  -123 -123 -124 -123 -123 ...
##  $ Proportion_of_native_species: num  0.94 0.77 0.61 0.66 0.75 0.53 0.41 0.47 0.62 0.54 ...
##  $ Cultural_species_richness   : num  2.71 2.8 2.43 1.07 3.6 0.8 1.56 1.5 3.6 3.57 ...
##  $ Exotic_species              : num  0.17 11.17 27.19 31.51 8.8 ...
##  $ Trampling                   : num  5 5.4 7.71 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 0 4.71 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 2 1.4 1 1.6 0.8 0.4 1 1 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 77 61 66 75 53 41 47 62 54 ...
# step 2
geo_eccc_sites_2 <- geo_eccc_sites_2[order(geo_eccc_sites_2$Restoration_Intensity),]

# values in order now -- ?? how to change to reverse order 
site_restInt_bar <- ggplot(geo_eccc_sites_2,
       aes(y = reorder(Restoration_Intensity, desc(Restoration_Intensity)), color = Site, fill = Site)) +
  # reorder y variable axis
  # https://stackoverflow.com/questions/28391850/reverse-order-of-discrete-y-axis-in-ggplot2s
# y = Restoration_Intensity
                    geom_bar() +
  #geom_bar(stat="identity") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="bottom") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Site by Restoration_Intensity',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-26", y = "Restoration_Intensity")
site_restInt_bar

ggplotly(site_restInt_bar)

4.8 Violin Subregion by Exotic_species

subregion_exsp <- ggplot(geo_eccc, 
                    aes(x = Subregion, y = Exotic_species)) +
                    geom_violin(fill = "seagreen2") +
                    geom_boxplot(width = 0.1, fill = "sandybrown") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(vjust = 1, size = 9)) +
                    labs(title='Plotting Subregion by Exotic_species',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_exsp

# plotly won't work here

4.9 Violin Subregion by Percentage_ns

names(geo_eccc)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
subregion_nsp <- ggplot(geo_eccc, 
                    aes(x = Subregion, y = Percentage_ns)) +
                    geom_violin(fill = "seagreen2") +
                    geom_boxplot(width = 0.1, fill = "sandybrown") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(vjust = 1, size = 9)) +
                    labs(title='Plotting Subregion by Percentage of Native Species',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-27")
subregion_nsp

# plotly won't work here

4.10 Cowplot Violin Subregion plot_grid

library(cowplot)

subregion_exsp_1 <- subregion_exsp + labs(title='Exotic Species',
                      subtitle='ECCC',
                      caption = "2025-08-27")

subregion_nsp_1 <- subregion_nsp + labs(title='Native Species',
                      subtitle='ECCC',
                      caption = "2025-08-27")

plot_grid(subregion_exsp_1, subregion_nsp_1, labels = "AUTO")

4.11 TEST NOTWorking Bar Chart Subregion by Restoration_Intensity

names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
str(geo_eccc_sites_1)
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : num  94 55 62 77 61 66 75 53 32 64 ...
subregion_restInt <- ggplot(geo_eccc_sites_1, 
                    aes(y = Restoration_Intensity)) +
#                    geom_violin(fill = "seagreen2") +
                    geom_bar(width = 0.1, fill = "sandybrown") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Subregion by Restoration_Intensity',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-20")
subregion_restInt

ggplotly()
# plotly won't work here

4.12 Subregion by Proportion_of_native_species

subregion_natsp <- ggplot(geo_eccc_1, 
                    aes(x = Subregion, y = Percentage_ns)) +
                    geom_violin(fill = "seagreen2") +
                    geom_boxplot(width = 0.1, fill = "sandybrown") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Subregion by Proportion_of_native_species',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
subregion_natsp

4.13

5 Plots by Separate Sites

  • use pivot_longer() for single row with multiple columns convert to long

5.1 pivot longer one row to long df

colnames(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
# choose index row from data sorted alphabetically
# delete first 2 columns as they can't be characters ? also Proportion to leave Percentage 
# delete year column

# Anniversary_Island
Anniversary_Island <- geo_eccc_1[1, ]
Anniversary_Island
##      Subregion               Site Proportion_of_native_species
## 1 Gulf Islands Anniversary Island                         0.94
##   Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 1                      2.71           0.17         5      1.14             1.8
##   Year Percentage_ns
## 1 2023            94
Anniversary_Island <- Anniversary_Island[, -c(1,2,9)]
Anniversary_Island_long <- Anniversary_Island %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Anniversary_Island_long
## # A tibble: 7 × 2
##   variable                     value
##   <chr>                        <dbl>
## 1 Proportion_of_native_species  0.94
## 2 Cultural_species_richness     2.71
## 3 Exotic_species                0.17
## 4 Trampling                     5   
## 5 Herbivory                     1.14
## 6 Composite_Index               1.8 
## 7 Percentage_ns                94
# Gonzales
Gonzales <- geo_eccc_1[15, ]
Gonzales
##       Subregion      Site Proportion_of_native_species
## 15 Gulf Islands Owl Islet                         0.65
##    Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 15                         2          27.72     10.67      0.67             1.4
##    Year Percentage_ns
## 15 2023            65
Gonzales <- Gonzales[, -c(1,2,9)]
Gonzales
##    Proportion_of_native_species Cultural_species_richness Exotic_species
## 15                         0.65                         2          27.72
##    Trampling Herbivory Composite_Index Percentage_ns
## 15     10.67      0.67             1.4            65
Gonzales_long <- Gonzales %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Gonzales_long
## # A tibble: 7 × 2
##   variable                     value
##   <chr>                        <dbl>
## 1 Proportion_of_native_species  0.65
## 2 Cultural_species_richness     2   
## 3 Exotic_species               27.7 
## 4 Trampling                    10.7 
## 5 Herbivory                     0.67
## 6 Composite_Index               1.4 
## 7 Percentage_ns                65
# Uplands
Uplands <- geo_eccc_1[24, ]
Uplands
##            Subregion         Site Proportion_of_native_species
## 24 Saanich Peninsula Uplands Park                         0.37
##    Cultural_species_richness Exotic_species Trampling Herbivory Composite_Index
## 24                      1.45          49.38      2.36      5.82               1
##    Year Percentage_ns
## 24 2023            37
Uplands <- Uplands[, -c(1,2,9)]
Uplands
##    Proportion_of_native_species Cultural_species_richness Exotic_species
## 24                         0.37                      1.45          49.38
##    Trampling Herbivory Composite_Index Percentage_ns
## 24      2.36      5.82               1            37
Uplands_long <- Uplands %>% pivot_longer(everything(), names_to = "variable", values_to = "value")
Uplands_long
## # A tibble: 7 × 2
##   variable                     value
##   <chr>                        <dbl>
## 1 Proportion_of_native_species  0.37
## 2 Cultural_species_richness     1.45
## 3 Exotic_species               49.4 
## 4 Trampling                     2.36
## 5 Herbivory                     5.82
## 6 Composite_Index               1   
## 7 Percentage_ns                37

5.2 Point Plot Long Uplands

Uplands_long_plot  <-  ggplot(Uplands_long, 
                    aes(x = variable, y = value)) +
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_point() +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Uplands Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
Uplands_long_plot

5.3 Point Plot to Compare Gonzales Variables

Gonzales_long_plot  <-  ggplot(Gonzales_long, 
                    aes(x = variable, y = value)) +
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_point() +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Gonzales Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
Gonzales_long_plot

5.4 Point Plot Long Anniversary_Island_long

Anniversary_Island_long_plot  <-  ggplot(Anniversary_Island_long, 
                    aes(x = variable, y = value)) +
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_point() +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Plotting Anniversary Island Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-04")
Anniversary_Island_long_plot

5.5 Bar Variables Compare Uplands

compare_bar_uplands  <-  ggplot(Uplands_long, 
                    aes(x = variable, y = value)) +
  
# Exotic_species
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_bar(stat = "identity", fill = "seagreen") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Comparinging Uplands Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_bar_uplands

5.6 Compare Bar Variables multiple sites

names(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
compare_bar_multiple_sites  <-  ggplot(geo_eccc_1,
                    aes(x = Site, y = Percentage_ns, fill = Subregion)) +
  
# Exotic_species
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_bar(stat = "identity") +
  # Replace default palette of pink & blue
  scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Comparinging Site Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_bar_multiple_sites

5.7 Arrange Compare Bar Variables multiple sites

# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
names(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
# arrange values
#str(arr)
# geo_eccc_1 %>% arrange(Percentage_ns) -> arr
geo_eccc_1 %>% arrange(desc(Percentage_ns)) %>%
  # updates Site with new arrangement
   mutate(Site = factor(Site, levels = Site)) %>% 
    ggplot(
      aes(x = Site, y = Percentage_ns, fill = Subregion)) +
  # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
                    ylim(0, 100) +
                    geom_bar(stat = "identity") +
  # Replace default palette of pink & blue
  scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="bottom") + 
                    theme(axis.text.x = element_text(angle = 35, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Comparinging Sites',
                      subtitle='ECCC GOE Site Monitoring',
                      caption = "Chart by Wendy Anthony \n 2025-08-19")

5.8 TEST Stacking Bar Variables multiple sites

# https://r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html
# View(mpg)
# g <- ggplot(geo_eccc_1, aes(Subregion))  
# p <-  g + geom_bar(aes(fill = Site))
# ggplotly(p)
# 
# #https://stackoverflow.com/questions/6693257/making-a-stacked-bar-plot-for-multiple-variables-ggplot2-in-r
# dfr <- data.frame(
#   V1 = c(0.1, 0.2, 0.3),
#   V2 = c(0.2, 0.3, 0.2),
#   V3 = c(0.3, 0.6, 0.5),
#   V4 = c(0.5, 0.1, 0.7),
#   row.names = LETTERS[1:3]
# )
# 
# geo_eccc_2 <- subset(geo_eccc_1, , -c(Subregion))
# 
# geo_eccc_2 %>% rownames_to_column("ID") %>% pivot_longer(!ID) %>%
#   ggplot() +
#   geom_col(aes(x = ID, y = value, fill = name), position = 'fill')
# # Error in `pivot_longer_spec()`:
# #! Can't combine `Site` <character> and `Proportion_of_native_species` <double>.
# 
# names(geo_eccc_1)
#     ggplot(geo_eccc_1,
#       aes(x = Site, y = Percentage_ns, fill = Subregion, color = Subregion)) +
#   # https://www.sthda.com/english/wiki/ggplot2-axis-scales-and-transformations
#                     ylim(0, 100) +
#                     geom_bar(stat = "identity") +
#                     theme_minimal() + #get rid of grey background and tick marks 
#                     theme(legend.position="bottom") + 
#                     theme(axis.text.x = element_text(angle = 35, vjust = 1, hjust=1, size = 7)) +
#                     labs(title='Comparinging Sites',
#                       subtitle='ECCC GOE Site Monitoring',
#                       caption = "Chart by Wendy Anthony \n 2025-08-19")

5.9 ??? NOTWORKING Compare Column Variables Uplands

colnames(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
geo_eccc_1_filter <- filter(geo_eccc_1, geo_eccc_1$Site %in% c("Uplands Park", "Trial Island")) 


compare_col_uplands <- ggplot(geo_eccc_1_filter, 
  aes(Site, fill = Exotic_species)) + 
  geom_bar(position = "dodge", alpha = 0.5) +
                    theme_minimal() + #get rid of grey background and tick marks 
                    theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
                    labs(title='Comparinging Uplands Variables',
                      subtitle='ECCC',
                      caption = "Chart by Wendy Anthony \n 2025-08-08")
compare_col_uplands


6 TEST NOT WORKING Facet wraps

6.1 facet_wrap(~Subregion)

  • need to filter Subregion for each ???
names(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
ggplot(geo_eccc_1, 
       aes(x = Site, y = Exotic_species)) +
  geom_col() +
  facet_wrap(~Subregion) +
  theme(legend.position="none") + #remove legend 
   theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
   labs(title='Comparinging Uplands Variables',
      subtitle='ECCC',
      caption = "Chart by Wendy Anthony \n 2025-08-19")

6.2 ??? TEST FILTER SAME AS PREVIOUS NOT WORKINGfacet_wrap

  • need to filter Subregion for each ???
names(geo_eccc_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Proportion_of_native_species" "Cultural_species_richness"   
##  [5] "Exotic_species"               "Trampling"                   
##  [7] "Herbivory"                    "Composite_Index"             
##  [9] "Year"                         "Percentage_ns"
ggplot(geo_eccc_1, 
       aes(x = Site, y = Exotic_species)) +
  geom_col() +
  facet_wrap(~Subregion) +
  theme(legend.position="none") + #remove legend 
   theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
   labs(title='Comparinging Uplands Variables',
      subtitle='ECCC',
      caption = "Chart by Wendy Anthony \n 2025-08-19")


7 Test GGplot Function

7.1 Violin Chart Function

geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)
str(geo_eccc)
## 'data.frame':    24 obs. of  9 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion"                    "Site"                        
## [3] "Proportion_of_native_species" "Cultural_species_richness"   
## [5] "Exotic_species"               "Trampling"                   
## [7] "Herbivory"                    "Composite_Index"             
## [9] "Year"
subregion_var_violin <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){
  
    ggplot2::ggplot(file,
        ggplot2::aes(x = colx, y = coly)) +
    ggplot2::geom_violin(fill = "seagreen2") +
    ggplot2::geom_boxplot(width = 0.1, fill = "sandybrown") +
    ggplot2::theme_minimal() + #get rid of grey background and tick marks
    ggplot2::theme(legend.position="none") + #remove legend
    ggplot2::theme(
      axis.text.x = ggplot2::element_text(vjust = 1, hjust = .5, size = 8),
      axis.text.y = ggplot2::element_text(size = 5),
      plot.title = ggplot2::element_text(hjust = 0.5, size = 12),
      plot.subtitle = ggplot2::element_text(hjust = 0.5, size = 12)) +
    #theme(axis.text.x = element_text(angle = 25, vjust = 1, hjust=1, size = 7)) +
    ggplot2::labs(title=title,
         subtitle=subtitle,
         caption = caption,
         x = xlab, y = ylab)
  #subregion_exsp
  
}

subregion_var_violin(geo_eccc, 'Plotting Subregion by Exotic_species', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Exotic_species, "Subregion", "Exotic_species", "Chart by Wendy Anthony \n 2025-08-04")

subregion_var_violin(geo_eccc,'Plotting Subregion by Cultural_species_richness', 'ECCC Data Paper', geo_eccc$Subregion, geo_eccc$Cultural_species_richness, "Subregion", "Cultural_species_richness", "Chart by Wendy Anthony \n 2025-08-16")

7.2 Point Chart Function

7.2.1 ggplot point chart

geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)

str(geo_eccc)
## 'data.frame':    24 obs. of  9 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion"                    "Site"                        
## [3] "Proportion_of_native_species" "Cultural_species_richness"   
## [5] "Exotic_species"               "Trampling"                   
## [7] "Herbivory"                    "Composite_Index"             
## [9] "Year"
subregion_var_point <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){

ggplot(file, 
                    aes(x = colx, y = coly, colour = Subregion)) +
                    geom_point(shape = 18, size = 2) +
    # Replace default palette of pink & blue
    scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks
                    theme(legend.position="bottom") +
                    # theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle =35, vjust = 1, hjust=1, size = 7)) +
                    labs(title=title,
                      subtitle=subtitle,
                      caption = caption,
                      x = xlab, y = ylab)
}

subregion_var_point(geo_eccc,'Plotting Site by Percentage Native Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Proportion_of_native_species, "Site", "Proportion of native species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")

subregion_var_point(geo_eccc,'Plotting Site by Exotic Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Exotic_species, "Site", "Exotic Species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")

7.2.2 plotly ggplot point chart

geo_eccc <- read.csv("SiteData-TEST-GOE-Monitor.csv", header = TRUE, sep = ",", stringsAsFactors=FALSE)

str(geo_eccc)
## 'data.frame':    24 obs. of  9 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
names(geo_eccc)
## [1] "Subregion"                    "Site"                        
## [3] "Proportion_of_native_species" "Cultural_species_richness"   
## [5] "Exotic_species"               "Trampling"                   
## [7] "Herbivory"                    "Composite_Index"             
## [9] "Year"
subregion_var_point <- function(file, title, subtitle, colx, coly, xlab, ylab, caption){

ggplot(file, 
                    aes(x = colx, y = coly, colour = Subregion)) +
                    geom_point(shape = 18, size = 2) +
    # Replace default palette of pink & blue
    scale_fill_brewer(palette = "Dark2") +
                    theme_minimal() + #get rid of grey background and tick marks
                    theme(legend.position="bottom") +
                    # theme(legend.position="none") + #remove legend 
                    theme(axis.text.x = element_text(angle =35, vjust = 1, hjust=1, size = 7)) +
                    labs(title=title,
                      subtitle=subtitle,
                      caption = caption,
                      x = xlab, y = ylab)
}

p2 <- subregion_var_point(geo_eccc,'Plotting Site by Percentage Native Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Proportion_of_native_species, "Site", "Proportion of native species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")

subregion_var_point(geo_eccc,'Plotting Site by Exotic Species', 'Malloff & Shackelford. (2024). \nFeeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. \nRestoration Futures Lab at the University of Victoria.
', geo_eccc$Site, geo_eccc$Exotic_species, "Site", "Exotic Species", "Chart by Wendy Anthony \n 2025-09-16 \n ECCC Data: (Malloff & Shackelford, 2024)")

ggplotly(p2)

8 Leaflet Map

8.1 Custom Icons

Sites_eccc <- read.csv("SiteDetails-TEST-GOE-Monitor.csv", header = TRUE, sep = ",")

names(Sites_eccc)
## [1] "Subregion"             "Site"                  "Land.Manager"         
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"              
## [7] "Lat"                   "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map

# custom icon
# https://leafletjs.com/examples/custom-icons/
greenLeafIcon <- makeIcon(
  iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
  iconWidth = 38, iconHeight = 95,
  iconAnchorX = 22, iconAnchorY = 94,
  shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
  shadowWidth = 50, shadowHeight = 64,
  shadowAnchorX = 4, shadowAnchorY = 62
)
# change LeafIcon size 1/2
greenLeafIconSm <- makeIcon(
  iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png",
  iconWidth = 19, iconHeight = 47,
  iconAnchorX = 11, iconAnchorY = 47,
  shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png",
  shadowWidth = 25, shadowHeight = 32,
  shadowAnchorX = 2, shadowAnchorY = 31
)

# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
  

ECCC_map <- leaflet(Sites_eccc) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addMarkers(
             ~ Lng, ~ Lat, icon = greenLeafIconSm,
             popup = paste0("<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng,  "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
  setView(-123.44799, 48.64919, 9) %>%
  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
  addControl(title, position = "topright")

# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")

8.2 Circle Markers

# NOT WORKING - Sites not same
#geo_eccc_sites <- cbind(geo_eccc, Sites_eccc)
# try to add , "<br>",  "<b>Composite Index:</b> ", geo_eccc_sites$Composite_Index
# names(geo_eccc_sites)
names(Sites_eccc)
## [1] "Subregion"             "Site"                  "Land.Manager"         
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"              
## [7] "Lat"                   "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map


# Title control
title <- tags$div(HTML('<b>ECC Site Maps</b><br>Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria'))
 
# https://rstudio.github.io/leaflet/articles/markers.html 
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))

ECCC_map <- leaflet(Sites_eccc) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addCircleMarkers(
             ~ Lng, ~ Lat, radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
    color = ~pal(Subregion),
    stroke = FALSE, fillOpacity = 0.5,
             popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng,  "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
  setView(-123.44799, 48.64919, 9) %>%
  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
  addControl(title, position = "topright")

# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")

8.3 Circle Markers Sized to Area

names(Sites_eccc)
## [1] "Subregion"             "Site"                  "Land.Manager"         
## [4] "Main.Restoration.Type" "Restoration.Intensity" "Area.ha"              
## [7] "Lat"                   "Lng"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map


# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
 
# https://rstudio.github.io/leaflet/articles/markers.html 
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("green", "orange"), domain = c("Saanich Peninsula", "Gulf Islands"))

ECCC_map <- leaflet(Sites_eccc) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addCircleMarkers(
             ~ Lng, ~ Lat, 
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
              radius = ~geo_eccc$Composite_Index * 3,    
              # radius = ~Sites_eccc$Area.ha,
                  # radius = ~sqrt(Sites_eccc$Area.ha),
 # size smaller is Saanich, else larger if Gulf            
#             radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
    color = ~pal(Subregion),
    stroke = FALSE, fillOpacity = 0.5,
             popup = paste0("<b>Site:</b> ", Sites_eccc$Site, "<br>", "<b>Subregion:</b> ", Sites_eccc$Subregion, "<br>", "<b>Latitude:</b> ", Sites_eccc$Lat, "<br>", "<b>Longitude:</b> ", Sites_eccc$Lng,  "<br><br>", "<b>Land Manager:</b> ", Sites_eccc$Land.Manager, "<br>", "<b>Main Restoration:</b> ", Sites_eccc$Main.Restoration.Type, "<br>", "<b>Restoration Intensity:</b> ", Sites_eccc$Restoration.Intensity, "<br>", "<b> Area:</b> ", Sites_eccc$Area.ha, " ha")) %>%
  setView(-123.44799, 48.64919, 9) %>%
  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
  addControl(title, position = "topright")

# Display map
ECCC_map
# Save map
saveWidget(ECCC_map, "ECCC_map.html")

8.4 Circle Markers Sized to Composite_Index

geo_eccc_all_site_data.csv

geo_eccc_sites_1 <- read.csv("geo_eccc_all_site_data.csv")
names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map


# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- tags$div(HTML('<p style="font-size:12px;font-weight:bold">ECC Sites Map</p>'))
 
# https://rstudio.github.io/leaflet/articles/markers.html 
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("#d7191c", "#2c7bb6"), domain = c("Saanich Peninsula", "Gulf Islands"))

ECCC_map_1 <- leaflet(geo_eccc_sites_1) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addCircleMarkers(
             ~ Lng, ~ Lat, 
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
              radius = ~geo_eccc_sites_1$Composite_Index * 5,    
              # radius = ~geo_eccc_sites_1$Area.ha,
                  # radius = ~sqrt(geo_eccc_sites_1$Area.ha),
 # size smaller is Saanich, else larger if Gulf            
#             radius = ~ifelse(Subregion == "Saanich Peninsula", 4, 5),
    fillColor = ~pal(Subregion),
    color = "black",
    weight = 3, # size of circle border
    stroke = TRUE, fillOpacity = 0.5,
             popup = paste0("<b>Site:</b> ", "<b>", "<b>", geo_eccc_sites_1$Site, "</b>", "</b>", "<br><br>", "<b>Subregion:</b> ", geo_eccc_sites_1$Subregion, "<br>",
                        "<b>Latitude:</b> ", geo_eccc_sites_1$Lat, "<br>", "<b>Longitude:</b> ", geo_eccc_sites_1$Lng,  "<br><br>",
                        "<b>Land Manager:</b> ", geo_eccc_sites_1$Land_Manager, "<br>",
                        "<b>Main Restoration:</b> ", geo_eccc_sites_1$Main_Restoration_Type, "<br>",
                        "<b>Restoration Intensity:</b> ", geo_eccc_sites_1$Restoration_Intensity, "<br>",
                        "<b> Area:</b> ", geo_eccc_sites_1$Area_ha, " ha",
                        "<br><br>",
                        "<b>Proportion of native species:</b> ", geo_eccc_sites_1$Proportion_of_native_species, "<br>",
                        "<b>Cultural species richness:</b> ", geo_eccc_sites_1$Cultural_species_richness, "<br>",
                        "<b>Exotic species:</b> ", geo_eccc_sites_1$Exotic_species, "<br>",
                        "<b>Trampling:</b> ", geo_eccc_sites_1$Trampling, "<br>",
                        "<b>Herbivory:</b> ", geo_eccc_sites_1$Herbivory, "<br>",
                        "<b>Composite Index:</b> ", geo_eccc_sites_1$Composite_Index, "<br>")) %>%
  setView(-123.44799, 48.64919, 10) %>%
  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
  addControl(title, position = "topright")

# Display map
ECCC_map_1
# Save map
saveWidget(ECCC_map_1, "ECCC_map_CI.html")

8.5 Circle Markers Sized to Radius

8.5.1 Title code

geo_eccc_all_site_data.csv

geo_eccc_sites_1 <- read.csv("geo_eccc_all_site_data.csv")
names(geo_eccc_sites_1)
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
library(dplyr)
library(leaflet)
library(htmlwidgets) # for responsive web map


# Title control
# Malloff & Shackelford. (2024). Feeling the Pulse: Monitoring methods and initial outcomes in oak meadow ecosystems. Restoration Futures Lab at the University of Victoria
title <- '<p style="text-align: center; height: 30px; ">
<span style="font-size:10px;font-weight:bold; background-color: rgba(255, 255, 255, 0.9;");>ECCC GOE 2023 Monitoring Sites</span><br>
<span style="font-size:8px;font-style:italic; background-color: rgba(255, 255, 255, 0.9;">(Malloff & Shackelford, 2024)</span></p>'
 
# https://rstudio.github.io/leaflet/articles/markers.html 
# Create a palette that maps factor levels to colors
pal <- colorFactor(c("#d7191c", "#2c7bb6"), domain = c("Saanich Peninsula", "Gulf Islands"))

ECCC_map_2 <- leaflet(geo_eccc_sites_1) %>%
  addProviderTiles("Esri.WorldImagery") %>%
  addCircleMarkers(
             ~ Lng, ~ Lat, 
# https://stackoverflow.com/questions/40137212/variable-marker-size-feature-in-leaflet-r
#              radius = ~geo_eccc_sites_1$Composite_Index * 5,    
              # radius = ~geo_eccc_sites_1$Area.ha,
                  # radius = ~sqrt(geo_eccc_sites_1$Area.ha),
 # size smaller is Saanich, else larger if Gulf            
             radius = ~ifelse(Subregion == "Saanich Peninsula", 8, 8),
    fillColor = ~pal(Subregion),
    color = "black",
    weight = 3, # size of circle border
    stroke = TRUE, fillOpacity = 0.5,
             popup = paste0("<b>ECCC GOE 2023 Monitoring Data</b>", "<br>", "<i>(Malloff & Shackelford, 2024)</i>", "<br><br>",
               "<b>Site:</b> ", "<b>", geo_eccc_sites_1$Site, "</b>", "</b>", "<br><br>", "<b>Subregion:</b> ", geo_eccc_sites_1$Subregion, "<br>",
                        "<b>Latitude:</b> ", geo_eccc_sites_1$Lat, "<br>", "<b>Longitude:</b> ", geo_eccc_sites_1$Lng,  "<br><br>",
                        "<b>Land Manager:</b> ", geo_eccc_sites_1$Land_Manager, "<br>",
                        "<b>Main Restoration:</b> ", geo_eccc_sites_1$Main_Restoration_Type, "<br>",
                        "<b>Restoration Intensity:</b> ", geo_eccc_sites_1$Restoration_Intensity, "<br>",
                        "<b> Area:</b> ", geo_eccc_sites_1$Area_ha, " ha",
                        "<br><br>",
                        "<b>Proportion of native species:</b> ", geo_eccc_sites_1$Proportion_of_native_species, "<br>",
                        "<b>Cultural species richness:</b> ", geo_eccc_sites_1$Cultural_species_richness, "<br>",
                        "<b>Exotic species:</b> ", geo_eccc_sites_1$Exotic_species, "<br>",
                        "<b>Trampling:</b> ", geo_eccc_sites_1$Trampling, "<br>",
                        "<b>Herbivory:</b> ", geo_eccc_sites_1$Herbivory, "<br>",
                        "<b>Composite Index:</b> ", geo_eccc_sites_1$Composite_Index, "<br>")) %>%
  setView(-123.44799, 48.64919, 10) %>%
  # add controls
  addMiniMap(width = 150, height = 150, zoomLevelOffset = -4) %>%
  addControl(title, position = "topright")

# Display map
ECCC_map_2
# Save map
saveWidget(ECCC_map_2, "ECCC_map_radius-1.html")

9 Shiny

9.1 Shiny Gadget

9.1.1 lmGadget all sites

  • code works but can’t knit html file unless adding “echo=TRUE, eval = FALSE”

9.2 Inline Shiny app

9.2.1 Shiny Showcase

app-WORKS-TabsetLayout-choose-Reactive-Table-Plot-BoxNames-comments-showcase.R

## 
## Listening on http://127.0.0.1:5437

9.2.2 Reactive choose

## [1] "Subregion"                    "Site"                        
## [3] "Proportion_of_native_species" "Cultural_species_richness"   
## [5] "Exotic_species"               "Trampling"                   
## [7] "Herbivory"                    "Composite_Index"             
## [9] "Year"
## 'data.frame':    24 obs. of  9 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Gulf Islands" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Brackman Island" "Crows Nest" ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.77 0.66 0.75 0.53 0.45 0.65 0.62 0.58 ...
##  $ Cultural_species_richness   : num  2.71 1.3 2.8 1.07 3.6 0.8 0.42 2 3.6 2.33 ...
##  $ Exotic_species              : num  0.17 57.19 11.17 31.51 8.8 ...
##  $ Trampling                   : num  5 4.7 5.4 1.64 12.2 ...
##  $ Herbivory                   : num  1.14 36.5 0 26.71 0.1 ...
##  $ Composite_Index             : num  1.8 0.6 2 1 1.6 0.8 0.2 1.4 1 1 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
## 
## Listening on http://127.0.0.1:8245

9.2.3 Leaflet Reactive Site Details

app-leaflet-reactive-AllSiteDetails-WORKING

## 
## Attaching package: 'bslib'
## The following object is masked from 'package:utils':
## 
##     page
##  [1] "Subregion"                    "Site"                        
##  [3] "Land_Manager"                 "Main_Restoration_Type"       
##  [5] "Restoration_Intensity"        "Area_ha"                     
##  [7] "Lat"                          "Lng"                         
##  [9] "Proportion_of_native_species" "Cultural_species_richness"   
## [11] "Exotic_species"               "Trampling"                   
## [13] "Herbivory"                    "Composite_Index"             
## [15] "Year"                         "Percentage_ns"
## 'data.frame':    24 obs. of  16 variables:
##  $ Subregion                   : chr  "Gulf Islands" "Gulf Islands" "Saanich Peninsula" "Gulf Islands" ...
##  $ Site                        : chr  "Anniversary Island" "AVNR" "Bear Hill Park" "Brackman Island" ...
##  $ Land_Manager                : chr  "GINPR" "Saltspring conservancy" "CRD" "GINPR" ...
##  $ Main_Restoration_Type       : chr  "herbivore reduction" "herbivore reduction" "invasive removal" "invasive removal" ...
##  $ Restoration_Intensity       : chr  "high" "minimal" "low" "high" ...
##  $ Area_ha                     : num  4.39 20.54 3.8 4.41 10.1 ...
##  $ Lat                         : num  48.8 48.8 48.5 48.7 48.4 ...
##  $ Lng                         : num  -123 -123 -123 -123 -124 ...
##  $ Proportion_of_native_species: num  0.94 0.55 0.62 0.77 0.61 0.66 0.75 0.53 0.32 0.64 ...
##  $ Cultural_species_richness   : num  2.71 1.3 1.86 2.8 2.43 1.07 3.6 0.8 1 4.4 ...
##  $ Exotic_species              : num  0.17 57.19 24.46 11.17 27.19 ...
##  $ Trampling                   : num  5 4.7 7.57 5.4 7.71 1.64 12.2 16.6 10.4 6.2 ...
##  $ Herbivory                   : num  1.14 36.5 9.5 0 4.71 ...
##  $ Composite_Index             : num  1.8 0.6 1 2 1.4 1 1.6 0.8 0.4 1.6 ...
##  $ Year                        : int  2023 2023 2023 2023 2023 2023 2023 2023 2023 2023 ...
##  $ Percentage_ns               : int  94 55 62 77 61 66 75 53 32 64 ...
## 
## Listening on http://127.0.0.1:6254

9.2.4 Datatable search plot

app-datatable-search-plot-update-ECCC-TEST https://stackoverflow.com/questions/52880657/in-an-shiny-app-i-want-a-plot-to-update-based-on-the-search-results-in-a-datat

## 
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
## 
##     dataTableOutput, renderDataTable
## 
## Listening on http://127.0.0.1:7027

### Plot Select Axis Variables app4-SelectAxisVariables-WORKS.R - this shiny app won’t knit - looses connection ???

## 
## Attaching package: 'shinyscreenshot'
## The following object is masked from 'package:shiny':
## 
##     runExample
## 
## Listening on http://127.0.0.1:5987
## [1] "Exotic_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory
## Warning: Error in file: cannot open the connection
## [1] "Proportion_of_native_species"
## Warning in file(file, "rt"): cannot open file 'TEST-GOE-Monitor.csv': No such
## file or directory

## Warning in file(file, "rt"): Error in file: cannot open the connection

10 Mermaid Methods Flow Chart

10.1 Flow for ER390 Monitoring Data

DiagrammeR("
sequenceDiagram;
   Wendy->>HAT: ask for data;
   database->>HAT: monitoring data;
   database->>RStudio: upload and filter data;
   RStudio->>HAT: Report;
   HAT->>Wendy: data;
   alt monitoring data available
     RestorationTech->>database: upload data;
     RestorationTech->>Site: monitor;
     Site->>database: Site Monitoring Data;
     RStudio->>database: query data;
     Wendy->>RStudio: create data viz code;
   else data unavailable
     database->>RestorationTech: data not available;
     RestorationTech->>Site: remonitor;
     RestorationTech->>SiteCommunity: ask to remonitor;
     SiteCommunity->>RestorationTech: OK to remonitor;
   end
")

10.2 Graph for ER390 Methods Workflow

10.3 Examples

10.3.1 Example graph

DiagrammeR("
graph TB
 A-->B
 A-->C
 C-->E
 B-->D
 C-->D
 D-->F
 E-->F
")

10.3.2 example Diagrammer shapes

10.3.3 example Mermaid shapes

mermaid("
        graph BT
        A((Salinity))
        A-->B(Barnacles)
        B-.->|-0.10|B1{Mussels}
        A-- 0.30 -->B1
 
        C[Air Temp]
        C-->B
        C-.->E(Macroalgae)
        E-->B1
        C== 0.89 ==>B1
 
        style A fill:#FFF, stroke:#333, stroke-width:4px
        style B fill:#9AA, stroke:#9AA, stroke-width:2px
        style B1 fill:#879, stroke:#333, stroke-width:1px
        style C fill:#ADF, stroke:#333, stroke-width:2px
        style E fill:#9C2, stroke:#9C2, stroke-width:2px
 
        ")

10.3.4 Example sequenceDiagram

  DiagrammeR("
sequenceDiagram;
   customer->>ticket seller: ask for a ticket;
   ticket seller->>database: seats;
   alt tickets available
     database->>ticket seller: ok;
     ticket seller->>customer: confirm;
     customer->>ticket seller: ok;
     ticket seller->>database: book a seat;
     ticket seller->>printer: print a ticket;
   else sold out
     database->>ticket seller: none left;
     ticket seller->>customer: sorry;
   end
")

10.4 Gantt Charts for Timelines

10.4.1 Style Gantt code chunk

  • supposed to widen Gantt chart, but doesn’t

    Gantt Chart ER390

mermaid("
gantt
dateFormat  YYYY-MM-DD
title ER390 HAT Data Viz Project Timeline

section ER390 Project
  Nancy suggested Topic          :crit, done, first_7, 2025-07-22, 2025-07-23
  Talked to Vanessa at HAT       :crit, done, first_8, 2025-08-27,  2025-08-28
  Writing Proposal               :crit, active, first_9, 2025-08-27, 5d
  Start Project                        :active, first_10, 2025-09-03, 356d

section Important Things
  Applied For RNS Program         :crit, done, 2025-08-21, 24h
  Created Gantt Chart             :active, 2025-08-31, 24h

section Basic Tasks
  Creating RMarkdown code    :done, a1, 2025-08-04, 2025-08-31
  Writing Proposal            :active, after a1, 2025-08-31, 3d
  Email Nancy-RNS & Vanessa-HAT :active, 2025-09-02

section Shiny App
  Created Shiny App             :done, first_1, 2025-08-18, 2025-08-28
  Refining Shiny App            :active, first_5, 2025-08-18, 130d
  Interactive Data Table        :done, 2025-08-18, 2025-08-19

section RMarkdown
  Created Test Document         :done, first_6, 2025-08-04, 2025-08-05

section Shiny Clone
  Create Shiny Clone            :active, first_11, 2025-09-30, 150d

section Data Collection
  Collecting Example Data       :done, first_2, 2025-08-04, 10d
  Finish Collecting Data        : first_3, after first_2, 5d
  Do this after that            : first_4, after first_3, 5d

section Critical Tasks
  Completed, critical task      :done, done, import_1, 2025-08-18, 24h
  Also done, also critical      :active, done, import_2, after import_1, 2d
  Doing this important task now :active, active, import_3, after import_2, 3d
  Next critical task            :active, import_4, after import_3, 5d


section Interactive Data Viz
  First extras                  : extras_1, after import_4, 3d
  Second helping                : extras_2, after extras_1, 20h
  More of the extras            : extras_3, after extras_1, 48h
  
section The Extras
  Customize colours for HAT     :  2025-10-01, 2025-12-15
  Create R Package for HAT      :  2026-01-31, 2026-04-30


")

10.4.2 Gantt ER390 dataframe

ER390_gantt <- read.csv("ER390-Gantt-Tasks.csv", header = TRUE, sep = ",")

library(tidyr)
library(dplyr)
library(DiagrammeR)

mermaid(
  paste0(
    # mermaid "header", each component separated with "\n" (line break)
    "gantt", "\n",
    "dateFormat  YYYY-MM-DD", "\n",
    "title ER390 HAT Data Viz Project Timeline", "\n",
    # unite the first two columns (task & status) and separate them with ":"
    # then, unite the other columns and separate them with ","
    # this will create the required mermaid "body"
    paste(ER390_gantt %>%
            unite(i, task, status, sep = ":") %>%
            unite(j, i, pos, start, end, sep = ",") %>%
            .$j,
          collapse = "\n"
    ), "\n"
  )
)

10.4.3 Gantt ggplot 1

library(reshape2)
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(ggplot2)

tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfr <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)
mdfr <- melt(dfr, measure.vars = c("start.date", "end.date"))

gantt_ggplot <- ggplot(mdfr, aes(value, name, colour = is.critical)) + 
  geom_line(size = 6) +
  xlab(NULL) + 
  ylab(NULL)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
gantt_ggplot

# https://stackoverflow.com/questions/3550341/gantt-charts-with-r

tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfr <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)

ggplot(dfr, aes(x =start.date, xend= end.date, y=name, yend = name, color=is.critical)) +
  geom_segment(size = 6) +
  xlab(NULL) + ylab(NULL)

10.4.4 Gantt ggplot 2

library(reshape2)
tasks <- c("Review literature", "Mung data", "Stats analysis", "Write Report")
dfrP <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-24", "2010-10-01", "2010-11-01", "2011-02-14")),
  end.date    = as.Date(c("2010-10-31", "2010-12-14", "2011-02-28", "2011-04-30")),
  is.critical = c(TRUE, FALSE, FALSE, TRUE)
)
dfrR <- data.frame(
  name        = factor(tasks, levels = tasks),
  start.date  = as.Date(c("2010-08-22", "2010-10-10", "2010-11-01", NA)),
  end.date    = as.Date(c("2010-11-03", "2010-12-22", "2011-02-24", NA)),
  is.critical = c(TRUE, FALSE, FALSE,TRUE)
)
mdfr <- merge(data.frame(type="Plan", melt(dfrP, measure.vars = c("start.date", "end.date"))),
  data.frame(type="Real", melt(dfrR, measure.vars = c("start.date", "end.date"))), all=T)

library(ggplot2)
ggplot(mdfr, aes(x=value, y=type, color=is.critical))+
  geom_line(size=6)+
  facet_grid(name ~ .) +
  scale_y_discrete(limits=c("Real", "Plan")) +
  xlab(NULL) + ylab(NULL)
## Warning: Removed 2 rows containing missing values (`geom_line()`).

10.4.5 Gantt timevis interactive

# https://stackoverflow.com/questions/3550341/gantt-charts-with-r
library(timevis)
## 
## Attaching package: 'timevis'
## The following object is masked from 'package:shinyscreenshot':
## 
##     runExample
## The following object is masked from 'package:shiny':
## 
##     runExample
data <- data.frame(
  id      = 1:4,
  content = c("Item one"  , "Item two"  ,"Ranged item", "Item four"),
  start   = c("2016-01-10", "2016-01-11", "2016-01-20", "2016-02-14 15:00:00"),
  end     = c(NA          ,           NA, "2016-02-04", NA)
)

timevis(data)

11 TO DO

  • leaflet map jumps when clicking popup (in RStudio, not in html file)

11.1 DONE

11.1.1 to combine dataframes csv files to include site info

  1. make sure they each have same length number of unique rows
  2. arrange alphabetic order
  3. cbind
  4. remove duplicate columns

12 Session info

# to document specific packages used to run script
sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] timevis_2.1.0         reshape2_1.4.4        shinyscreenshot_0.2.0
##  [4] DT_0.26               bslib_0.4.0           htmlwidgets_1.5.4    
##  [7] leaflet_2.1.1         cowplot_1.1.1         DiagrammeR_1.0.9     
## [10] plotly_4.10.1         forcats_0.5.2         stringr_1.4.1        
## [13] dplyr_1.0.10          purrr_0.3.5           readr_2.1.3          
## [16] tidyr_1.2.1           tibble_3.1.8          ggplot2_3.4.0        
## [19] tidyverse_1.3.2       shiny_1.7.3          
## 
## loaded via a namespace (and not attached):
##  [1] fs_1.5.2                fontawesome_0.4.0       lubridate_1.8.0        
##  [4] webshot_0.5.4           RColorBrewer_1.1-3      httr_1.4.4             
##  [7] tools_4.2.1             backports_1.4.1         utf8_1.2.2             
## [10] R6_2.5.1                DBI_1.1.3               lazyeval_0.2.2         
## [13] colorspace_2.0-3        withr_2.5.0             processx_3.7.0         
## [16] tidyselect_1.2.0        compiler_4.2.1          textshaping_0.3.6      
## [19] cli_3.4.1               rvest_1.0.3             xml2_1.3.3             
## [22] labeling_0.4.2          sass_0.4.2              scales_1.2.1           
## [25] callr_3.7.2             systemfonts_1.0.4       digest_0.6.30          
## [28] rmarkdown_2.17          pkgconfig_2.0.3         htmltools_0.5.3        
## [31] dbplyr_2.2.1            fastmap_1.1.0           highr_0.9              
## [34] rlang_1.0.6             readxl_1.4.1            rstudioapi_0.14        
## [37] visNetwork_2.1.2        jquerylib_0.1.4         generics_0.1.3         
## [40] farver_2.1.1            jsonlite_1.8.2          crosstalk_1.2.0        
## [43] googlesheets4_1.0.1     magrittr_2.0.3          Rcpp_1.0.9             
## [46] munsell_0.5.0           fansi_1.0.3             lifecycle_1.0.3        
## [49] stringi_1.7.8           yaml_2.3.5              plyr_1.8.7             
## [52] grid_4.2.1              promises_1.2.0.1        crayon_1.5.2           
## [55] haven_2.5.1             hms_1.1.2               ps_1.7.1               
## [58] knitr_1.40              pillar_1.8.1            uuid_1.1-0             
## [61] markdown_1.1            reprex_2.0.2            glue_1.6.2             
## [64] evaluate_0.17           leaflet.providers_1.9.0 data.table_1.14.2      
## [67] modelr_0.1.9            vctrs_0.5.0             tzdb_0.3.0             
## [70] httpuv_1.6.6            cellranger_1.1.0        gtable_0.3.1           
## [73] assertthat_0.2.1        cachem_1.0.6            xfun_0.37              
## [76] mime_0.12               xtable_1.8-4            broom_1.0.1            
## [79] later_1.3.0             ragg_1.2.3              googledrive_2.0.0      
## [82] viridisLite_0.4.1       gargle_1.2.1            memoise_2.0.1          
## [85] ellipsis_0.3.2